//
//  SetViewController.m
//  InviteJob
//
//  Created by LangLang on 17/10/26.
//  Copyright © 2017年 Shui. All rights reserved.
//

#import "SetViewController.h"
#import "ChangePasswordViewController.h"
#import "FeedbackViewController.h"
#import "CleanCaches.h"

@interface SetViewController ()

@end

@implementation SetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = strColor(@"f6f6f6");
    TitleView(@"设置")
}


- (IBAction)passwdOnClick:(id)sender {
    ChangePasswordViewController *passwd = [ChangePasswordViewController new];
    [self.navigationController pushViewController:passwd animated:YES];
}


- (IBAction)feedbackOnClick:(id)sender {
    FeedbackViewController *feedback = [FeedbackViewController new];
    [self.navigationController pushViewController:feedback animated:YES];
}

- (IBAction)clearCacheOnClick:(id)sender {
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *cachesDir = [paths objectAtIndex:0];
    float size = [CleanCaches folderSizeAtPath:cachesDir];
    
 
    
    UIAlertController *actionSheetController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:[NSString stringWithFormat:@"当前缓存%.2lfM",size]  preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *determineAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"清除" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
         [CleanCaches clearCache:cachesDir];
        
         SHuiMBhudTextTimeStr(@"清除成功");
    
    }];
    
    [actionSheetController addAction:determineAction];
    [actionSheetController addAction:cancelAction];
    
    [self presentViewController:actionSheetController animated:YES completion:nil];
    
}

- (IBAction)btnOutLogin:(id)sender {
    
    UIAlertController *actionSheetController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"退出登录？"  preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *determineAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
        isUser
        NSString *strUrl = [NSString stringWithFormat:user_userLoginOut_api];
        NSDictionary *parameter = @{@"user_id":user.user_id,
                                    @"token":user.token};
        [PostNetWorking postNetWorkingStr:strUrl andparameters:parameter Success:^(id responseObject) {
            [UserManager clearUserInfo];
            SHuiMBhudTextTimeStr(@"退出成功");
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [self.navigationController popViewControllerAnimated:YES];
            });
        } failed:^(NSError *error) {
            SHuiMBhudTextTimeStr(@"网络错误");
        }];
        
    }];
    
    [actionSheetController addAction:determineAction];
    [actionSheetController addAction:cancelAction];
    
    [self presentViewController:actionSheetController animated:YES completion:nil];
    
    
    
}



@end
